﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OgilvyOne.Ext.Weibo.Common;
using OgilvyOne.Ext.Weibo.Lib;
using OgilvyOne.Ext.Weibo.Model;
using OgilvyOne.Model;

public partial class flashInterface : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Weiboinfo wb1 = new Weiboinfo();
        //OAuthAccessToken Otoken = new OAuthAccessToken();
        //Otoken.Token = "2.00VcXYICUIiAiD6b3e9dff3bAbDYOC";
        //wb1.WeiboToken = Otoken;
        //wb1.WeiboUID = "1958708743";
        //Session["weibo"] = wb1;
        //Session["guid"] = "380a0ca1-bfab-4418-8c9d-d4943f8fca86";

        //Statuses template = new Statuses();
        //template = Microblog.GetMentions(wb1.WeiboToken, null, null, 1, 200); //@我的

        string guid = Request.QueryString["guid"];
        if (Session["weibo"] != null) //获取登录用户的微博数据
        {
            //OgilvyOne.BLL.DataCache.RemoveCache(Session["guid"].ToString()); //清楚缓存
            object ojb = OgilvyOne.BLL.DataCache.GetCache(Session["guid"].ToString());
            var sb = new StringBuilder();
            Response.ContentType = "text/xml";
            Response.ContentEncoding = Encoding.UTF8;
            sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            sb.AppendLine(@"<root>");
            Weiboinfo wb = new Weiboinfo();
            wb = (Session["weibo"] as Weiboinfo);
            GetUserInfo(wb.WeiboToken, wb.WeiboUID);        //获取用户信息
        }
    }

    /// <summary>
    /// 取用户的信息
    /// </summary>
    /// <param name="token"></param>
    /// <param name="uid"></param>
    /// <returns></returns>
    public string GetUserInfo(OAuthAccessToken token, string uid)
    {
        var sb = new StringBuilder();
        Int64 IntUid;
        Int64.TryParse(uid, out IntUid);
        UserInfo user = Microblog.GetUserInfo(token, IntUid);
        sb.AppendLine(@"<result>1</result>");
        sb.AppendLine(string.Format("<guid>{0}</guid>", Session["guid"].ToString()));
        sb.AppendLine(@"<userinfo>");
        sb.AppendLine(string.Format("<id>{0}</id>", user.ID.ToString()));
        sb.AppendLine(string.Format("<screenname>{0}</screenname>", user.ScreenName));
        sb.AppendLine(string.Format("<address>{0}</address>", user.Location));
        sb.AppendLine(string.Format("<headerimg>{0}</headerimg>", user.AvatarLarge));
        sb.AppendLine(@"</userinfo>");
        return sb.ToString();
    }

    /// <summary>
    /// 取粉丝
    /// </summary>
    /// <param name="wb"></param>
    /// <param name="flag"></param>
    //public string GetMyFansFromSina(Weiboinfo wb,bool flag)
    //{

    //}

    //public static Users GetmyFans(Weiboinfo wb, int pageIndex, int count, Func<T, R> r)
    //{

    //}


}